$(function () {
    $(window).resize();
});

function formatDate(now) {
    var year = now.getFullYear();  //取得4位数的年份
    var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
    var date = now.getDate();      //返回日期月份中的天数（1到31）
    var hour = now.getHours();     //返回日期中的小时数（0到23）
    var minute = now.getMinutes(); //返回日期中的分钟数（0到59）
    var second = now.getSeconds(); //返回日期中的秒数（0到59）
    return year + "年" + month + "月" + date + "日" + hour + ":" + minute + ":" + second;
}

var abc;
var annotations = null;
$(window).resize(function () {
    $(".body-content").css("height", $(window).height() - 20);
    var h = $(".body-content").height() - $("#carDetailDiv").outerHeight(true) - 30; //左上块的高度
    $("#carPicDiv").css("height", h);//给左上块高度赋值
    $("#carPicContainer").css("height", h - 80);//总高度去除人脸基本信息高度  赋值
    $("#carScenePic").css("height", h - 100);  //去掉按钮的div中 图片的高度
    $("#carcheckPic").css("height", (h - 110) / 2); //车辆检图额高度
    $("#cardNumPic").css("height", (h - 110) / 2);//车牌图的高度
    var h2 = $(".body-content").height() - $("#sameTimeMACDiv").outerHeight(true) - 200;
    $("#sameTimeCarDiv").css("height", h2);
    drawLine(oneCarToInfo.image);
});
var oneCarToInfo = {
    playerObj: null,
    result: null,
    historytime1: '',  //历史回放开始时间
    historytime2: '',   //历史回放结束时间
    ssid: '',
    time: '',
    deviceid: '',
    beginTime: '',
    endTime: new Date().Format('yyyy-MM-dd') + ' 23:59:59',
    image: {},
    userName: getUrlParam("user") === undefined || getUrlParam("user") == "" ? "default" : getUrlParam("user"),
    page: 1,
    plateNo: getUrlParam("plateNo"),
    plateColor: getUrlParam("plateColor"),
    totalPages: 0,
    recordPage: 1,
    recordTotalPages: 0,
    day: 10,
    wfRecordPage: 1,
    wfRecordTotalPages: 0,
    recordArr: [],
    wsgChecked: false,
    mzChecked: false,
    zdhpChecked: false,
    chdChecked: false,
    wfjlChecked: [],
    bzChecked: [],
    bzDeviceID: '',
    _index: 1,
    bzCheckedInfo: [],
    probability: 0,
    functions: {
        init: function () {
            oneCarToInfo.ssid = getUrlParam("ssid");  //url截取ssid对应的值
            oneCarToInfo.time = decodeURIComponent(getUrlParam("time"));//url截取time对应的值
            oneCarToInfo.time = oneCarToInfo.time.replace(/-/g, "/"); //兼容ie
            oneCarToInfo.deviceid = getUrlParam("deviceId");//url截取deviceid对应的值
            oneCarToInfo.beginTime = getUrlParam("beginTime");
            this.getCarInfo(window.parent.ztcObj.dataArr[window.parent.ztcObj.index]);//获取车辆详情
            this.jzljc();
            this.ZYZ();
            this.YCDH();
            //有无准运证
            this.licenseData(decodeURIComponent(oneCarToInfo.plateNo));
            //初始化最近十天的数据记录
            this.areaRecord(oneCarToInfo.recordPage, oneCarToInfo.plateNo, oneCarToInfo.plateColor, oneCarToInfo.day);
            //过车记录
            this.theMonthData(oneCarToInfo.page, oneCarToInfo.plateNo, oneCarToInfo.plateColor);
            this.getBiaozhuInfo();//获取标注特征
            this.initjump();//按钮跳转
            //美化滚动条
            $("#tab_clxx").niceScroll({
                cursorcolor: "#ddd",
                cursorborder: "0px solid #ddd"
            });
            $("#checkAll").prop("checked", "checked");
            $(".claj_tab3_txt").hide();
        },
        imgerror: function (obj) {
            $(obj).attr('src', '/vias_app/static/vias/images/getphotoerr.jpg');
            $("#findCarWithPe").addClass('layui-btn-disabled');
            $("#findCarWithPe").attr("disabled", 'disabled');
        },

        initjump: function () {
            //以图找车
            $("#findCarWithPe").off('click').on('click', function () {
                var message = {
                    src: serUrl_port7 + 'vias_app/views/vias/snapshot/motorvehicle/searchCarWithPic.html',
                    name: '以图找车',
                    params: {
                        url: encodeURIComponent($("#carScenePic").attr('src'))
                    }
                }
                window.open('../motorvehicle/searchCarWithPic.html?url=' + encodeURIComponent($("#carScenePic").attr('src')));
            });
            //车辆轨迹
            $("#followTarget").off('click').on('click', function () {
                var data = {
                    plateNo: oneCarToInfo.plateNo,
                    plateColor: oneCarToInfo.plateColor,
                    beginTime: oneCarToInfo.beginTime,
                    endTime: oneCarToInfo.endTime,
                    deviceId: oneCarToInfo.deviceid,
                    vehicleClassType: oneCarToInfo.vehicleClassType, // 车辆类型
                    vehicleColor: oneCarToInfo.vehicleColor,   // 车身颜色
                    vehicleBrand: oneCarToInfo.vehicleBrand,   // 车辆品牌
                }
                window.open('../../technicaltactics/vehicletrack/vehicletrack.html?plateNo=' + oneCarToInfo.plateNo + '&plateColor=' + oneCarToInfo.plateColor
                    + '&vehicleClassType=' + oneCarToInfo.vehicleClassType + '&vehicleColor=' + oneCarToInfo.vehicleColor + '&vehicleBrand=' + oneCarToInfo.vehicleBrand
                    + '&beginTime=' + oneCarToInfo.beginTime + '&endTime=' + oneCarToInfo.endTime + '&deviceId=');
            });
            //落脚点
            $("#getEndpointInfo").off('click').on('click', function () {
                window.open('../../technicaltactics/endpoint/endpoint.html?plateNo=' + oneCarToInfo.plateNo + '&plateColor=' + oneCarToInfo.plateColor);
            });
            //区域碰撞
            $("#areaTractCrash").off('click').on('click', function () {
                window.open('../../topic/areatractcrash/areaTractCrash.html?plateNo=' + oneCarToInfo.plateNo + '&plateColor=' + oneCarToInfo.plateColor);
            });
            // 伴随车辆
            $("#vehicleFollow").off('click').on('click', function () {
                window.open('../../technicaltactics/vehiclefollow/vehiclefollow.html?plateNo=' + oneCarToInfo.plateNo + '&plateColor=' + oneCarToInfo.plateColor);
            });
            //快速布控
            $("#fastReact").off('click').on('click', function () {
                var paramobj = {
                    token: getUrlParam('token'),
                    imageAddress1: $("#carScenePic").attr('src'),
                    imageAddress2: $("#carScenePic").attr('src'),
                    platNo: $("#carnum").text(),
                    name: '',
                    sex: '',
                    idcard: '',
                    birthday: '',
                    platColor: $("#carcolor").text()
                };
                fastReact.reactChoose('car', paramobj);
            });
            //图像增强
            $("#picStrong").off('click').on('click', function () {
                var message = {
                    src: serUrl_port8 + 'txzqserver/txzq/index',
                    name: '图像增强',
                    params: {
                        url: encodeURIComponent($("#carScenePic").attr('src'))
                    }
                }
                window.parent.parent.postMessage(message, '*');
            });
            //一车一档
            $("#onecaronedetail").off('click').on('click', function () {
                var message = {
                    plateNum: $("#carnum").text(),
                    plateType: $("#plate_type").val()
                }
                oneCaroneDetail(message);//公共方法中
            });
            //特征标注
            $("#updateStatus").off('click').on('click', function () {
                layui.use('layer', function () {
                    oneCarToInfo._index = layer.open({
                        type: 1,
                        title: '进行特征标注',
                        area: ['400px', '260px'],
                        shade: 0.6,
                        shadeClose: true,
                        closeBtn: 1,
                        scrollbar: false,
                        content: '<div id="bzDiv" style="height:100%;width:100%;overflow:hidden;background-color: #073d63;">' +
                            '<div class="cars_tr_check">' +
                            '<input id="checklay1" type="checkbox"' + (oneCarToInfo.bzCheckedInfo.indexOf(1) == -1 ? '' : 'checked') + ' name="bzCheck"><label for="checklay1"><i></i>未苫盖</label><br>' +
                            '<input id="checklay2" type="checkbox"' + (oneCarToInfo.bzCheckedInfo.indexOf(2) == -1 ? '' : 'checked') + ' name="bzCheck"><label for="checklay2"><i></i>满载</label><br>' +
                            '<input id="checklay3" type="checkbox"' + (oneCarToInfo.bzCheckedInfo.indexOf(3) == -1 ? '' : 'checked') + ' name="bzCheck"><label for="checklay3"><i></i>遮挡号牌</label><br>' +
                            '<input id="checklay4" type="checkbox"' + (oneCarToInfo.bzCheckedInfo.indexOf(4) == -1 ? '' : 'checked') + ' name="bzCheck"><label for="checklay4"><i></i>闯红灯</label><br>' +
                            '<button class="cars_bq_label" id="biaozhu" style="margin-left: 260px;" onclick="oneCarToInfo.functions.biaozhuClick()">标注</button>' +
                            '</div>' +
                            '</div>',
                        cancel: function (index, layero) {
                            layer.close(index)
                        }
                    });
                });
            });
            //历史回放
            $("#historyPlay").off('click').on('click', function () {
                var parma = '?time=' + encodeURIComponent(oneCarToInfo.time)
                    + '&deviceId=' + oneCarToInfo.deviceid;
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.open({
                        type: 2,
                        fixed: true,
                        title: ['历史视频记录', 'font-size: 22px;color: rgb(49, 70, 89);'],
                        closeBtn: 1,
                        scrollbar: false,
                        maxmin: false,
                        content: './playhistory.html' + parma,
                        area: ['816px', '636px'],
                        cancel: function (index, layero) {
                            window["layui-layer-iframe" + index].videostopreal(); 
                        }
                    });
                });
            });
            $("#checklay1").off('click').on('click', function () {
                if ($(this).attr("checked") == 'checked') {
                    $(this).removeAttr("checked");
                } else {
                    $(this).attr("checked", "checked");
                }
            });
            $("#checklay2").off('click').on('click', function () {
                if ($(this).attr("checked") == 'checked') {
                    $(this).removeAttr("checked");
                } else {
                    $(this).attr("checked", "checked");
                }
            });
            $("#checklay3").off('click').on('click', function () {
                if ($(this).attr("checked") == 'checked') {
                    $(this).removeAttr("checked");
                } else {
                    $(this).attr("checked", "checked");
                }
            });
            $("#checklay4").off('click').on('click', function () {
                if ($(this).attr("checked") == 'checked') {
                    $(this).removeAttr("checked");
                } else {
                    $(this).attr("checked", "checked");
                }
            });
            $("#videoback").off('click').on('click', function () {
                var browser = navigator.userAgent;
                if (browser.indexOf('Trident') == -1) {
                    layui.use('layer', function () {
                        layer.msg('视频在Chrome内核下无法播放', { icon: 5 });
                    });
                    return false;
                }
                // window.open('http://15.225.15.13/vias_app/views/vias/snapshot/face/video.html');
                // return false;
                layui.use('layer', function () {
                    layer.open({
                        type: 1,
                        area: ['1200px', '800px'],
                        shade: 0.6,
                        shadeClose: true,
                        title: '',
                        closeBtn: 0,
                        content: '<div style="height:100%;width:100%;overflow:hidden;">' +
                            '<object style="height:100%;width:100%;" id="video" classID="CLSID:B0F9AA50-FB5E-4DB8-A33F-273834EBDBAE">' +
                            '<param name="MainServerIP" id="theforever" value="15.225.11.3"/>' +
                            '<param name="HasBakServer" value="0"/>' +
                            '<param name="BakServerIP" value="127.0.0.1"/>' +
                            '<param name="ShowCtrlPane" value="0"/>' +
                            '<param name="ShowMenu" value="0"/>' +
                            '<param name="SetWorkType" value="0"/>' +
                            '</object>' +
                            '</div>',
                        success: function (layno, index) {
                            setTimeout('register(oneCarToInfo.deviceid)', 1000);
                        },
                        end: function () {
                            var stopflag = oneCarToInfo.playerObj.MS_StopClient();
                            if (stopflag != 0) {
                                console.log('关闭失败');
                            } else {
                                console.log('关闭成功');
                            }
                        }
                    });
                });
            });
            //最近十天
            $("#ten_days").off('click').on('click', function () {
                oneCarToInfo.recordPage = 1;
                oneCarToInfo.day = 10;
                oneCarToInfo.functions.areaRecord(oneCarToInfo.recordPage, oneCarToInfo.plateNo, oneCarToInfo.plateColor, oneCarToInfo.day);
            });
            //最近一个月
            $("#one_month").off('click').on('click', function () {
                oneCarToInfo.recordPage = 1;
                oneCarToInfo.day = 30;
                oneCarToInfo.functions.areaRecord(oneCarToInfo.recordPage, oneCarToInfo.plateNo, oneCarToInfo.plateColor, oneCarToInfo.day);
            });
            //最近半年
            $("#half_a_year").off('click').on('click', function () {
                oneCarToInfo.recordPage = 1;
                oneCarToInfo.day = 180;
                oneCarToInfo.functions.areaRecord(oneCarToInfo.recordPage, oneCarToInfo.plateNo, oneCarToInfo.plateColor, oneCarToInfo.day);
            });
        },
        getBiaozhuInfo: function () {
            $.ajax({
                type: 'get',
                dataType: "json",
                data: {
                    plateNo: oneCarToInfo.plateNo, //车牌号码
                    pass_time: $("#pass_time").text(), //经过时间
                },
                url: serUrl_port2 + "/VIAS/web/snapshot/Specialnote/Judgemark",
                success: function (data) {
                    if (data.length) {
                        $.each(data, function (i, row) {
                            oneCarToInfo.bzCheckedInfo.push(row.ANNOTATION_TYPE)
                        });
                    }
                }
            });
        },
        //标注
        biaozhuClick: function () {
            var obj = document.getElementsByName("bzCheck");
            var check_val = [];
            for (k in obj) {
                if (obj[k].checked)
                    check_val.push(Number(k) + 1);
            }
            $.ajax({
                type: 'POST',
                dataType: "json",
                data: {
                    plateNo: oneCarToInfo.plateNo, //车牌号码
                    labelTypes: check_val.join(','),//标注类型
                    pass_time: $("#pass_time").text(), //经过时间
                    img: $("#carScenePic").attr("src"),//照片
                    devcieid: oneCarToInfo.bzDeviceID,//设备id
                    ssId: window.parent.ztcObj.dataArr[window.parent.ztcObj.index].SS_ID,
                },
                url: serUrl_port2 + "/VIAS/web/snapshot/Specialnote/addAnnotations",
                success: function (data) {
                    if (data) {
                        alert("标注成功");
                        oneCarToInfo.bzCheckedInfo = check_val;
                    } else {
                        alert("标注失败");
                    }
                }
            });
            layer.close(oneCarToInfo._index);
        },
        jzljc: function () {
            $.ajax({
                type: "GET",
                dataType: "json",
                data: {
                    cph: abc
                },
                url: serUrl_port9 + "/VIAS/web/ztc/findMotorVehicleJZLJBycph",
                success: function (data) {
                    console.log(data);
                    if (data.length > 0) {
                        $("#tab1_baoben").show();
                        var unixTimestamp = new Date(data[0].CDSJ);
                        var birthday = formatDate(unixTimestamp);
                        $("#QYMC").text(data[0].QYMC);
                        $("#LXR").text(data[0].LXR);
                        $("#LXDH_1").text(data[0].LXDH);
                        $("#QYDZ").text(data[0].QYDZ);
                        $("#YYZZ").text(data[0].YYZZ);
                        $("#PPXH").text(data[0].PPXH);
                        $("#CLLX").text(data[0].CLLX);
                        $("#CLYS").text(data[0].CPYS);
                        $("#RYLX").text(data[0].RYLX);
                        $("#CDSJ").text(birthday);
                        $("#PFBZ").text(data[0].PFBZ);
                        $("#ZY_ZL").text(data[0].ZY_ZL);
                    } else {
                        $("#tab1_baoben").hide();
                    }
                }
            });

        },
        ZYZ: function () {
            $.ajax({
                type: "GET",
                dataType: "json",
                data: {
                    ch: abc
                },
                url: serUrl_port9 + "/VIAS/web/ztc/findMotorVehicleZYZBycph",
                success: function (data) {
                    console.log(data);
                    oneCarToInfo.functions.licenseData(abc);
                    if (data.length > 0) {
                        $("#tab1_zhunyz").show();
                        var unixTimestamp = new Date(data[0].SPSJ);
                        var birthday = formatDate(unixTimestamp);
                        var unixTimestamp = new Date(data[0].YXQ);
                        var birthday1 = formatDate(unixTimestamp);
                        $("#SSYSQYMC").text(data[0].SSYSQYMC);
                        $("#SPQX").text(data[0].SPQX);
                        $("#SPSJ").text(birthday);
                        $("#CLSYR").text(data[0].CLSYR);
                        $("#LXFS").text(data[0].LXDH);
                        $("#YXQ").text(birthday1);
                    } else {
                        $("#tab1_zhunyz").hide();
                    }


                }
            });

        },
        YCDH: function () {
            $.ajax({
                type: "GET",
                dataType: "json",
                data: {
                    cph: abc
                },
                url: serUrl_port9 + "/VIAS/web/ztc/findMotorVehicleYCDHBycph",
                success: function (data) {
                    console.log(data);
                    //console.log(data[0].CLPP);
                    if (data.length > 0) {
                        $("#tab1_zhuce").show();
                        var unixTimestamp = new Date(data[0].CDRQ);
                        var birthday = formatDate(unixTimestamp);
                        var unixTimestamp = new Date(data[0].GXRQ);
                        var birthday_1 = formatDate(unixTimestamp);
                        $("#CLPP").text(data[0].CLPP);
                        $("#LXDZ").text(data[0].LXDZ);
                        $("#SYR").text(data[0].SYR);
                        $("#LXDH").text(data[0].LXDH);
                        $("#CLLX").text(data[0].CLLX);
                        $("#HPZL").text(data[0].HPZL);
                        $("#RYZL").text(data[0].RYZL);
                        $("#ZT").text(data[0].ZT);
                        $("#CDRQ").text(birthday);
                        $("#GXRQ").text(birthday_1);
                    } else {
                        $("#tab1_zhuce").hide();
                    }


                }
            });

        },

        getCarInfo: function (data) {
            oneCarToInfo.vehicleClassType = data.VEHICLE_CLASS;
            oneCarToInfo.vehicleColor = data.VEHICLE_COLOR;
            oneCarToInfo.vehicleBrand = data.VEHICLE_BRAND;
            oneCarToInfo.vehicleBrandCH = data.VEHICLE_BRAND_TRANSLATION;
            //在获取img地址后，动态加载放大镜文件
            $.getScript("/vias_app/static/plugin/jqzoom/xq_bigimg.js", function () {
            });
            if (data) {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    data: {
                        VEHICLE_CLASS: data.VEHICLE_CLASS,
                        PLATE_COLOR: data.PLATE_COLOR,
                        VEHICLE_COLOR: data.VEHICLE_COLOR,
                        PENDANT: data.PENDANT,
                        CALLING: data.CALLING,
                        sSAFETY_BELT: data.SAFETY_BELT,
                        SUNVISOR: data.SUNVISOR,
                        VICE_SUNVISOR: data.VICE_SUNVISOR,
                        DIRECTION: data.DIRECTION,
                        YELLOR_LABLE: data.YELLOR_LABLE,
                        DANGER_VEHICLE: data.DANGER_VEHICLE,
                        SS_PLATFORM_IDENT: data.SS_PLATFORM_IDENT
                    },
                    url: serUrl_port2 + "/VIAS/web/snapshot/MotorVehicle/findDictionaryByMap",
                    success: function (data) {
                        console.log(data);
                        if (data) {
                            $("#cartype").text(data.VEHICLE_CLASS_TRANSLATION);
                            $("#platecolor").text(data.PLATE_COLOR_TRANSLATION);
                            $("#carbodycolor").text(data.VEHICLE_COLOR_TRANSLATION);
                            $("#pendant").text(data.PENDANT_TRANSLATION);
                            $("#calling").text(data.CALLING_TRANSLATION);
                            $("#sunvisor").text(data.SUNVISOR_TRANSLATION);
                            $("#vice_sunvisor").text(data.VICE_SUNVISOR_TRANSLATION);
                            $("#direction").text(data.DIRECTION_TRANSLATION);
                            $("#yellor_lable").text(data.YELLOR_LABLE_TRANSLATION);
                            $("#danger_vehicle").text(data.DANGER_VEHICLE_TRANSLATION);
                            $("#sourceid").text(data.SS_PLATFORM_IDENT_TRANSLATION);
                            $("#safety_belt").text(data.SAFETY_BELT_TRANSLATION);
                        }
                    }
                });
                console.log(data.PLATE_NO);
                abc = data.PLATE_NO;

                $("#carnum").text(data.PLATE_NO);
                $("#carbrand").text(data.VEHICLE_BRAND_TRANSLATION);
                $("#carbrands").text(data.VEHICLE_SUB_BRAND).attr("title", data.VEHICLE_SUB_BRAND);
                $("#tissue_box").text('未知');
                $("#annual_inspection_mark").text('未知');
                $("#vice_safety_belt").text('未知');
                $("#speed").text(data.SPEED);
                $("#lane_no").text('未知');
                $("#pass_time").text(data.PASS_TIME);
                $("#ss_ape_name").text(data.SS_APE_NAME).attr("title", data.SS_APE_NAME);

                $("#passadress").text('未知');
                $("#carcheckPic").attr('src', '../../../../static/images/wutu.jpg'); //车辆检图
                $("#cardNumPic").attr('src', '../../../../static/images/wutu.jpg'); //车牌图
                $("#carScenePic").attr("src", data.STORAGE_URL3);//场景图
                oneCarToInfo.bzDeviceID = data.DEVICE_ID;
                oneCarToInfo.image.leftTopX = data.LEFT_TOP_X;
                oneCarToInfo.image.leftTopY = data.LEFT_TOP_Y;
                oneCarToInfo.image.rightBottomX = data.RIGHT_BTM_X;
                oneCarToInfo.image.rightBottomY = data.RIGHT_BTM_Y;
                drawLine(oneCarToInfo.image);
                oneCarToInfo.plateNo = data.PLATE_NO;
                oneCarToInfo.plateColor = data.PLATE_COLOR;
            }
        },
        changeImg: function (url, lx, ly, rx, ry) {
            $("#carScenePic").attr("src", url);//场景图
            oneCarToInfo.image.leftTopX = lx;
            oneCarToInfo.image.leftTopY = ly;
            oneCarToInfo.image.rightBottomX = rx;
            oneCarToInfo.image.rightBottomY = ry;
            drawLine(oneCarToInfo.image);
        },
        prevDetail: function () {
            oneCarToInfo.bzCheckedInfo = [];
            window.parent.ztcObj.index--;
            var index = window.parent.ztcObj.index;
            if (index < 0) {
                index = window.parent.ztcObj.dataArr.length - 1;
                window.parent.ztcObj.index = index;
            }
            oneCarToInfo.functions.getCarInfo(window.parent.ztcObj.dataArr[index]);
            oneCarToInfo.functions.jzljc();
            oneCarToInfo.functions.ZYZ();
            oneCarToInfo.functions.YCDH();
            oneCarToInfo.functions.theMonthData(oneCarToInfo.page, oneCarToInfo.plateNo, oneCarToInfo.plateColor);
            oneCarToInfo.functions.areaRecord(oneCarToInfo.recordPage, oneCarToInfo.plateNo, oneCarToInfo.plateColor, oneCarToInfo.day);
            $("#ten_days").parent("a").addClass("sec").siblings("a").removeClass("sec");
            oneCarToInfo.page = 1;
        },
        nextDetail: function () {
            oneCarToInfo.bzCheckedInfo = [];
            window.parent.ztcObj.index++;
            var index = window.parent.ztcObj.index;
            if (index >= window.parent.ztcObj.dataArr.length) {
                index = 0;
                window.parent.ztcObj.index = index;
            }
            oneCarToInfo.functions.getCarInfo(window.parent.ztcObj.dataArr[index]);
            oneCarToInfo.functions.jzljc();
            oneCarToInfo.functions.ZYZ();
            oneCarToInfo.functions.YCDH();
            oneCarToInfo.functions.theMonthData(oneCarToInfo.page, oneCarToInfo.plateNo, oneCarToInfo.plateColor);
            oneCarToInfo.functions.areaRecord(oneCarToInfo.recordPage, oneCarToInfo.plateNo, oneCarToInfo.plateColor, oneCarToInfo.day);
            $("#ten_days").parent("a").addClass("sec").siblings("a").removeClass("sec");
            oneCarToInfo.page = 1;
        },
        //准运证判断
        licenseData: function (plateNo) {
            $.ajax({
                type: 'get',
                dataType: "json",
                data: {
                    CH: plateNo, //车牌号码kb  
                    ctTime: $("#pass_time").text(),
                },
                url: serUrl_port2 + "/VIAS/web/snapshot/Specialnote/findVehicleLicense",
                success: function (data) {
                    if (data) {
                        $("#license").text("有");
                    } else {
                        $("#license").text("无");
                    }
                }
            });
        },
        //近一个月的过车记录
        theMonthData: function (page, plateNo, plateColor) {
            $(".claj_tab3_txt").hide();
            $.ajax({
                type: 'get',
                dataType: "json",
                data: {
                    page: page,
                    rows: 6,
                    plateNo: plateNo, //车牌号码
                    beginTime: "",//开始日期
                    endTime: "",//结束日期
                    plateColor: plateColor,//车牌颜色
                    userName: oneCarToInfo.userName,
                },
                url: serUrl_port2 + "/VIAS/web/snapshot/MotorVehicleRecord/findTheMonthMotorRecord",
                success: function (data) {
                    if (data.rows.length > 0) {
                        var _html = "";
                        $.each(data.rows, function (i, row) {
                            _html += `<div class="cars_tr_item"><div><span>${row.PASS_TIME}</span><img src="${row.STORAGE_URL1}" onclick="oneCarToInfo.functions.changeImg('${row.STORAGE_URL3}','${row.LEFT_TOP_X}','${row.LEFT_TOP_Y}','${row.RIGHT_BTM_X}','${row.RIGHT_BTM_Y}')"><p title="${row.SS_APE_NAME}">${row.SS_APE_NAME}</p></div></div>`;
                        });
                        $("#cars_tr_imgs").empty().html(_html);
                        oneCarToInfo.totalPages = data.totalPages;
                    } else {
                        var noResult = '<div class="list_res_empty">' +
                            ' <div></div>' +
                            ' </div>';
                        $("#cars_tr_imgs").empty().html(noResult);
                    }
                }
            });
        },
        //过车记录上一页
        pagesLeft: function () {
            if ($("#check1").attr("checked") || $("#check2").attr("checked") || $("#check3").attr("checked") || $("#check4").attr("checked")) {
                this.check1PagesLeft();
            } else {
                if (oneCarToInfo.page <= 1) {
                    return;
                }
                oneCarToInfo.page = oneCarToInfo.page - 1;
                oneCarToInfo.functions.theMonthData(oneCarToInfo.page, oneCarToInfo.plateNo, oneCarToInfo.plateColor);

            }
        },
        // 过车记录下一页
        pagesRight: function () {
            if ($("#check1").attr("checked") || $("#check2").attr("checked") || $("#check3").attr("checked") || $("#check4").attr("checked")) {
                this.check1PagesRight();
            } else {
                if (oneCarToInfo.page >= oneCarToInfo.totalPages) {
                    return;
                }
                oneCarToInfo.page = oneCarToInfo.page + 1;
                oneCarToInfo.functions.theMonthData(oneCarToInfo.page, oneCarToInfo.plateNo, oneCarToInfo.plateColor);

            }
        },
        //活动区域及出行时间
        areaRecord: function (page, plateNo, plateColor, day) {
            $.ajax({
                type: 'get',
                dataType: "json",
                data: {
                    page: page,
                    rows: 6,
                    plateNo: plateNo, //车牌号码
                    beginTime: "",//开始日期
                    endTime: "",//结束日期
                    plateColor: plateColor,//车牌颜色
                    userName: oneCarToInfo.userName,
                    day: day
                },
                url: serUrl_port2 + "VIAS/web/snapshot/MotorVehicleRecord/findTheHourMotorRecord",
                success: function (data) {
                    if (data.rows.length > 0) {
                        data.rows.sort(compare('COUNT_NUMBER'));
                        //    渲染预判数据  在后台中已经把数据写在了data.rows的最后的一条
                        if (oneCarToInfo.day == 10) {
                            oneCarToInfo.recordArr = data.rows.slice(0, data.rows.length - 1);
                            var anticipationMap = data.rows[data.rows.length - 1];
                            var SS_APE_NAME = anticipationMap.SS_APE_NAME === undefined ? '未知设备' : anticipationMap.SS_APE_NAME;
                            $("#anticipation").text(anticipationMap.PASS_TIME + "日" + anticipationMap.HOUR + "点在  " + SS_APE_NAME + " 出现");
                            oneCarToInfo.probability = parseInt(anticipationMap.PROBABILITY);

                            var dom = document.getElementById("container");
                            var myChart = echarts.init(dom);
                            var probability = 100 - oneCarToInfo.probability;
                            option = {
                                series: [
                                    {
                                        name: '',
                                        type: 'pie',
                                        radius: ['70%', '75%'],
                                        avoidLabelOverlap: false,
                                        label: {
                                            normal: {
                                                show: false,
                                                position: 'center'
                                            },
                                        },
                                        data: [
                                            {
                                                value: probability, name: '未出现概率', itemStyle: {
                                                    color: "#1f9cac"
                                                }
                                            },
                                            {
                                                value: oneCarToInfo.probability,
                                                name: '出现概率',
                                                itemStyle: {
                                                    borderWidth: 4,
                                                    color: "#47fbff",
                                                    borderColor: "#47fbff"
                                                }
                                            }
                                        ]
                                    }
                                ]
                            };
                            if (option && typeof option === "object") {
                                myChart.setOption(option, true);
                            }
                            //环状图
                            $(".huan_text b span").text(oneCarToInfo.probability);
                        } else {
                            oneCarToInfo.recordArr = data.rows;
                        }
                        var startRow = (page - 1) * 6;
                        var endRow = startRow + 6;
                        var tempData = oneCarToInfo.recordArr.slice(startRow, endRow);
                        var _html = "";
                        $.each(tempData, function (i, row) {
                            _html += `<div class="cars_br_item"><span title="${row.PASS_TIME}" class="cars_br_time">${row.HOUR}</span><span class="cars_br_addr">${row.SS_APE_NAME === undefined ? '未知设备' : row.SS_APE_NAME}</span><span class="cars_br_count">${row.COUNT_NUMBER}次</span></div>`;
                        });
                        $("#cars_br_con").empty().html(_html);
                        oneCarToInfo.recordPage = 1;
                        oneCarToInfo.recordTotalPages = data.totalPages;
                    } else {
                        var noResult = '<div class="list_res_empty">' +
                            ' <div></div>' +
                            ' </div>';
                        $("#cars_br_con").empty().html(noResult);
                    }
                }
            });
        },
        //活动区域及出行时间 上一页
        prev: function () {
            if (oneCarToInfo.recordPage <= 1) {
                return;
            }
            oneCarToInfo.recordPage = oneCarToInfo.recordPage - 1;
            var startRow = (oneCarToInfo.recordPage - 1) * 6;
            var endRow = startRow + 6;
            var tempData = oneCarToInfo.recordArr.slice(startRow, endRow);
            var _html = "";
            $.each(tempData, function (i, row) {
                _html += `<div class="cars_br_item"><span class="cars_br_time">${row.HOUR}</span><span class="cars_br_addr">${row.SS_APE_NAME === undefined ? '未知设备' : row.SS_APE_NAME}</span><span class="cars_br_count">${row.COUNT_NUMBER}次</span></div>`;
            });
            $("#cars_br_con").empty().html(_html);
        },
        // 活动区域及出行时间 下一页
        next: function () {
            if (oneCarToInfo.recordPage >= oneCarToInfo.recordTotalPages) {
                return;
            }
            oneCarToInfo.recordPage = oneCarToInfo.recordPage + 1;
            var startRow = (oneCarToInfo.recordPage - 1) * 6;
            var endRow = startRow + 6;
            var tempData = oneCarToInfo.recordArr.slice(startRow, endRow);
            var _html = "";
            $.each(tempData, function (i, row) {
                _html += `<div class="cars_br_item"><span class="cars_br_time">${row.HOUR}</span><span class="cars_br_addr">${row.SS_APE_NAME === undefined ? '未知设备' : row.SS_APE_NAME}</span><span class="cars_br_count">${row.COUNT_NUMBER}次</span></div>`;
            });
            $("#cars_br_con").empty().html(_html);
        },
        carsCheck1Record: function (page, plateNo, wfjlChecked) {
            var ZPLX = "";
            $.ajax({
                type: 'get',
                dataType: "json",
                data: {
                    page: page,
                    rows: 6,
                    plateNo: plateNo, //车牌号码
                    labelTypes: wfjlChecked
                },
                url: serUrl_port2 + "/VIAS/web/snapshot/Specialnote/getAnnotations",

                success: function (data) {
                    console.log(data);
                    if (data.rows.length > 0) {
                        $(".claj_tab3_txt").show();
                        var _html = "";
                        annotations = data.rows[0];
                        $.each(data.rows, function (i, row) {
                            _html += `<div class="cars_tr_item" annotations="${row.ANNOTATION_TYPE}" ><div><span>${row.PASS_TIME}</span><img src="${row.SS_IMAGE_ADDR_A}"><p title="${row.DEVCIE_ID}">${row.DEVCIE_ID}</p></div></div>`;
                        });
                        $("#ZPSJ").text(annotations.PASS_TIME);
                        $("#ZPDD").text(annotations.DEVCIE_ID);

                        if (annotations.ANNOTATION_TYPE == 1) {
                            ZPLX = "未苫盖";
                        }
                        if (annotations.ANNOTATION_TYPE == 2) {
                            ZPLX = "满载";
                        }
                        if (annotations.ANNOTATION_TYPE == 3) {
                            ZPLX = "遮挡号牌";
                        }
                        if (annotations.ANNOTATION_TYPE == 4) {
                            ZPLX = "闯红灯";
                        }
                        $("#ZPLX").text(ZPLX);
                        $("#cars_tr_imgs").empty().html(_html);
                        oneCarToInfo.wfRecordTotalPages = data.totalPages;
                    } else {
                        $(".claj_tab3_txt").hide();
                        var noResult = '<div class="list_res_empty">' +
                            ' <div></div>' +
                            ' </div>';
                        $("#cars_tr_imgs").empty().html(noResult);
                    }
                }
            });
        },
        checkEdStatus: function () {

            if (oneCarToInfo.wsgChecked && oneCarToInfo.wfjlChecked.indexOf(1) == -1) {
                oneCarToInfo.wfjlChecked.push(1);

            } else if (!oneCarToInfo.wsgChecked) {
                if (oneCarToInfo.wfjlChecked.indexOf(1) != -1) {
                    oneCarToInfo.wfjlChecked.splice(oneCarToInfo.wfjlChecked.indexOf(1), 1);
                }
            }
            if (oneCarToInfo.mzChecked && oneCarToInfo.wfjlChecked.indexOf(2) == -1) {
                oneCarToInfo.wfjlChecked.push(2);
            } else if (!oneCarToInfo.mzChecked) {
                if (oneCarToInfo.wfjlChecked.indexOf(2) != -1) {
                    oneCarToInfo.wfjlChecked.splice(oneCarToInfo.wfjlChecked.indexOf(2), 1);
                }
            }
            if (oneCarToInfo.zdhpChecked && oneCarToInfo.wfjlChecked.indexOf(3) == -1) {
                oneCarToInfo.wfjlChecked.push(3);
            } else if (!oneCarToInfo.zdhpChecked) {
                if (oneCarToInfo.wfjlChecked.indexOf(3) != -1) {
                    oneCarToInfo.wfjlChecked.splice(oneCarToInfo.wfjlChecked.indexOf(3), 1);
                }
            }
            if (oneCarToInfo.chdChecked && oneCarToInfo.wfjlChecked.indexOf(4) == -1) {
                oneCarToInfo.wfjlChecked.push(4);
            } else if (!oneCarToInfo.chdChecked) {
                if (oneCarToInfo.wfjlChecked.indexOf(4) != -1) {
                    oneCarToInfo.wfjlChecked.splice(oneCarToInfo.wfjlChecked.indexOf(4), 1);
                }
            }
            if (!oneCarToInfo.wsgChecked && !oneCarToInfo.mzChecked && !oneCarToInfo.zdhpChecked && !oneCarToInfo.chdChecked) {
                $("#checkAll").prop("checked", "checked");
                this.theMonthData(oneCarToInfo.page, oneCarToInfo.plateNo, oneCarToInfo.plateColor);
            }
        },
        checkAll: function () {
            oneCarToInfo.wfRecordPage = 1;

            if ($("#checkAll").prop("checked")) {
                $("#checkAll").prop("checked", "checked");
            } else {
                $("#checkAll").prop("checked", "checked");
            }
            if ($("#check1").prop("checked")) {
                $("#check1")[0].checked = false;
            }
            if ($("#check2").prop("checked")) {
                $("#check2")[0].checked = false;
            }
            if ($("#check3").prop("checked")) {
                $("#check3")[0].checked = false;
            }
            if ($("#check4").prop("checked")) {
                $("#check4")[0].checked = false;
            }
            oneCarToInfo.wsgChecked = false;
            oneCarToInfo.mzChecked = false;
            oneCarToInfo.zdhpChecked = false;
            oneCarToInfo.chdChecked = false;
            oneCarToInfo.functions.checkEdStatus();
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
        // 选择未苫盖
        check1: function () {
            oneCarToInfo.wfRecordPage = 1;
            if ($("#check1").prop("checked")) {
                $("#check1").prop("checked", "checked");
                if ($("#checkAll").prop("checked")) {
                    $("#checkAll")[0].checked = false;
                }
                oneCarToInfo.wsgChecked = true;
            } else {
                $("#check1").removeAttr("checked");
                oneCarToInfo.wsgChecked = false;
            }
            oneCarToInfo.functions.checkEdStatus();
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
        // 选择满载
        check2: function () {
            oneCarToInfo.wfRecordPage = 1;
            if ($("#check2").prop("checked")) {
                $("#check2").prop("checked", "checked");
                if ($("#checkAll").prop("checked")) {
                    $("#checkAll")[0].checked = false;
                }
                oneCarToInfo.mzChecked = true;
            } else {
                $("#check2").removeAttr("checked");
                oneCarToInfo.mzChecked = false;
            }
            oneCarToInfo.functions.checkEdStatus();
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
        // 选择遮挡号牌
        check3: function () {
            oneCarToInfo.wfRecordPage = 1;
            if ($("#check3").prop("checked")) {
                $("#check3").prop("checked", "checked");
                if ($("#checkAll").prop("checked")) {
                    $("#checkAll")[0].checked = false;
                }
                oneCarToInfo.zdhpChecked = true;
            } else {
                $("#check3").removeAttr("checked");
                oneCarToInfo.zdhpChecked = false;
            }
            oneCarToInfo.functions.checkEdStatus();
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
        // 选择闯红灯
        check4: function () {
            oneCarToInfo.wfRecordPage = 1;
            if ($("#check4").prop("checked")) {
                $("#check4").prop("checked", "checked");
                if ($("#checkAll").prop("checked")) {
                    $("#checkAll")[0].checked = false;
                }
                oneCarToInfo.chdChecked = true;
            } else {
                $("#check4").removeAttr("checked");
                oneCarToInfo.chdChecked = false;
            }
            oneCarToInfo.functions.checkEdStatus();
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
        //标注上一页
        check1PagesLeft: function () {
            oneCarToInfo.functions.checkEdStatus();
            if (oneCarToInfo.wfRecordPage <= 1) {
                return;
            }
            oneCarToInfo.wfRecordPage = oneCarToInfo.wfRecordPage - 1;
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
        // 标注下一页
        check1PagesRight: function () {
            oneCarToInfo.functions.checkEdStatus();
            if (oneCarToInfo.wfRecordPage >= oneCarToInfo.wfRecordTotalPages) {
                return;
            }
            oneCarToInfo.wfRecordPage = oneCarToInfo.wfRecordPage + 1;
            oneCarToInfo.functions.carsCheck1Record(oneCarToInfo.wfRecordPage, oneCarToInfo.plateNo, oneCarToInfo.wfjlChecked.join(","));
        },
    }
};
var aflag = true;

function register(deviceid) {
    console.log('设备id：' + deviceid);
    oneCarToInfo.playerObj = document.getElementById("video");
    oneCarToInfo.result = oneCarToInfo.playerObj.MS_StartClient('SUPPER_NONEED_USER', '');
    if (oneCarToInfo.result != 0) {
        console.log("MS_StartClient接口错误！错误码：", result);
        setTimeout(function () {
            oneCarToInfo.functions.register();
        }, 500);
    }
    oneCarToInfo.playerObj.MS_SetLayoutMode(1);
    oneCarToInfo.playerObj.ms_setcurrentlayout(0);
    var starttime = videotime(oneCarToInfo.historytime1), endtime = videotime(oneCarToInfo.historytime2);
    setTimeout(function () {
        var playid = oneCarToInfo.playerObj.MS_PlayBackbyTime(deviceid, starttime, endtime, 0);  //31011820180623000001   31011813001320029052
        //var playid = oneCarToInfo.playerObj.MS_SetCameraToWindow('31011820180623000001',0);
        if (playid < 0) {
            console.log("MS_PlayBackbyTime", playid);
        }
    }, 1000)
}

function videotime(time) {
    if (time != "") {
        var timearr = [];
        timearr.push(time.substring(0, 4));
        timearr.push(time.substring(5, 7));
        timearr.push(time.substring(8, 10));
        timearr.push(time.substring(11, 13));
        timearr.push(time.substring(14, 16));
        timearr.push(time.substring(17, 19));
        return timearr.join(',');
    } else {
        return "";
    }
}



